home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
- /* do.c - version 1.0.3 */
-
- /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) and 't' (throw) */
-
- #include "hack.h"
-
- extern struct obj *splitobj(), *addinv();
- extern boolean hmon();
- extern boolean level_exists[];
- extern struct monst youmonst;
- extern char *nomovemsg;
-
- dodrop() {
- return(drop(getobj("0$#", "drop")));
- }
-
- static
- drop(obj) register struct obj *obj; {
- if(!obj) return(0);
- if(obj->olet == '$') { /* pseudo object */
- register long amount = OGOLD(obj);
-
- if(amount == 0)
- pline("You didn't drop any gold pieces.");
- else {
- mkgold(amount, u.ux, u.uy);
- pline("You dropped %ld gold piece%s.",
- amount, plur(amount));
- if(Invisible) newsym(u.ux, u.uy);
- }
- free((char *) obj);
- return(1);
- }
- if(obj->owornmask & (W_ARMOR | W_RING)){
- pline("You cannot drop something you are wearing.");
- return(0);
- }
- if(obj == uwep) {
- if(uwep->cursed) {
- pline("Your weapon is welded to your hand!");
- return(0);
- }
- setuwep((struct obj *) 0);
- }
- pline("You dropped %s.", doname(obj));
- dropx(obj);
- return(1);
- }
-
- /* Called in several places - should not produce texts */
- dropx(obj)
- register struct obj *obj;
- {
- freeinv(obj);
- dropy(obj);
- }
-
- dropy(obj)
- register struct obj *obj;
- {
- if(obj->otyp == CRYSKNIFE)
- obj->otyp = WORM_TOOTH;
- obj->ox = u.ux;
- obj->oy = u.uy;
- obj->nobj = fobj;
- fobj = obj;
- if(Invisible) newsym(u.ux,u.uy);
- subfrombill(obj);
- stackobj(obj);
- }
-
- /* drop several things */
- doddrop() {
- return(ggetobj("drop", drop, 0));
- }
-
- dodown()
- {
- if(u.ux != xdnstair || u.uy != ydnstair) {
- pline("You can't go down here.");
- return(0);
- }
- if(u.ustuck) {
- pline("You are being held, and cannot go down.");
- return(1);
- }
- if(Levitation) {
- pline("You're floating high above the stairs.");
- return(0);
- }
-
- goto_level(dlevel+1, TRUE);
- return(1);
- }
-
- doup()
- {
- if(u.ux != xupstair || u.uy != yupstair) {
- pline("You can't go up here.");
- return(0);
- }
- if(u.ustuck) {
- pline("You are being held, and cannot go up.");
- return(1);
- }
- if(!Levitation && inv_weight() + 5 > 0) {
- pline("Your load is too heavy to climb the stairs.");
- return(1);
- }
-
- goto_level(dlevel-1, TRUE);
- return(1);
- }
-
- goto_level(newlevel, at_stairs)
- register int newlevel;
- register boolean at_stairs;
- {
- register fd;
- register boolean up = (newlevel < dlevel);
-
- if(newlevel <= 0) done("escaped"); /* in fact < 0 is impossible */
- if(newlevel > MAXLEVEL) newlevel = MAXLEVEL; /* strange ... */
- if(newlevel == dlevel) return; /* this can happen */
-
- glo(dlevel);
- fd = creat(lock, FMASK);
- if(fd < 0) {
- /*
- * This is not quite impossible: e.g., we may have
- * exceeded our quota. If that is the case then we
- * cannot leave this level, and cannot save either.
- * Another possibility is that the directory was not
- * writable.
- */
- pline("A mysterious force prevents you from going %s.",
- up ? "up" : "down");
- return;
- }
-
- if(Punished) unplacebc();
- u.utrap = 0; /* needed in level_tele */
- u.ustuck = 0; /* idem */
- keepdogs();
- seeoff(1);
- if(u.uswallow) /* idem */
- u.uswldtim = u.uswallow = 0;
- flags.nscrinh = 1;
- u.ux = FAR; /* hack */
- (void) inshop(); /* probably was a trapdoor */
-
- savelev(fd,dlevel);
- (void) close(fd);
- dlevel = newlevel;
- if(maxdlevel < dlevel)
- maxdlevel = dlevel;
- glo(dlevel);
-
- if(!level_exists[dlevel]) mklev();
- else {
- extern int hackpid;
-
- #ifdef TOS
- if((fd = open(lock,0x8000)) < 0) { /*no translate*/
- #else
- if((fd = open(lock,0)) < 0) {
- #endif
- pline("Cannot open %s .", lock);
- pline("Probably someone removed it.");
- done("tricked");
- }
- getlev(fd, hackpid, dlevel);
- (void) close(fd);
- }
-
- if(at_stairs) {
- if(up) {
- u.ux = xdnstair;
- u.uy = ydnstair;
- if(!u.ux) { /* entering a maze from below? */
- u.ux = xupstair; /* this will confuse the player! */
- u.uy = yupstair;
- }
- if(Punished && !Levitation){
- pline("With great effort you climb the stairs.");
- placebc(1);
- }
- } else {
- u.ux = xupstair;
- u.uy = yupstair;
- if(inv_weight() + 5 > 0 || Punished){
- pline("You fall down the stairs."); /* %% */
- losehp(rnd(3), "fall");
- if(Punished) {
- if(uwep != uball && rn2(3)){
- pline("... and are hit by the iron ball.");
- losehp(rnd(20), "iron ball");
- }
- placebc(1);
- }
- selftouch("Falling, you");
- }
- }
- { register struct monst *mtmp = m_at(u.ux, u.uy);
- if(mtmp)
- mnexto(mtmp);
- }
- } else { /* trapdoor or level_tele */
- do {
- u.ux = rnd(COLNO-1);
- u.uy = rn2(ROWNO);
- } while(levl[u.ux][u.uy].typ != ROOM ||
- m_at(u.ux,u.uy));
- if(Punished){
- if(uwep != uball && !up /* %% */ && rn2(5)){
- pline("The iron ball falls on your head.");
- losehp(rnd(25), "iron ball");
- }
- placebc(1);
- }
- selftouch("Falling, you");
- }
- (void) inshop();
- initrack();
-
- losedogs();
- { register struct monst *mtmp;
- if(mtmp = m_at(u.ux, u.uy)) mnexto(mtmp); /* riv05!a3 */
- }
- flags.nscrinh = 0;
- setsee();
- seeobjs(); /* make old cadavers disappear - riv05!a3 */
- docrt();
- pickup(1);
- read_engr_at(u.ux,u.uy);
- }
-
- donull() {
- return(1); /* Do nothing, but let other things happen */
- }
-
- dopray() {
- nomovemsg = "You finished your prayer.";
- nomul(-3);
- return(1);
- }
-